#include "loginwindow.h"
#include "mainwindow.h"
#include "../parser.h"
#include "../logger.h"
#include <gtkmm/main.h>

LoginWindow::LoginWindow(BaseObjectType* cobject,
						 const Glib::RefPtr<Gnome::Glade::Xml>& ui_xml)
	: Gtk::Dialog(cobject),
	  connect_button_(0),
	  quit_button_(0)
{
	ui_xml->get_widget("connect_button", connect_button_);
	connect_button_->signal_clicked().connect(
		sigc::mem_fun(*this, &LoginWindow::on_connect));
	ui_xml->get_widget("quit_button", quit_button_);
	quit_button_->signal_clicked().connect(sigc::ptr_fun(Gtk::Main::quit));
	ui_xml->get_widget("student_id_text_entry", student_id_);
}

LoginWindow::~LoginWindow()
{
}

/// Handler for the signal emitted when the user clicks the Connect button.
void LoginWindow::on_connect()
{
    // parse data in xml files
    Parser::instance()->prefix("../data");
    Parser::instance()->courses("courses.xml");
    Parser::instance()->student("student.xml");

	if( Parser::instance()->parse() )
		Logger::instance()->message("XML parsed successfully.", 1);
    else
        Logger::instance()->error("XML was not parsed successully.", 1);

	hide();
	Glib::RefPtr<Gnome::Glade::Xml> ui_xml =
		Gnome::Glade::Xml::create("main_window.glade");
	MainWindow* main_window = 0;
	ui_xml->get_widget_derived("main_window", main_window);

    main_window->show();
}
